package name.marz.to.go.ahg.common.util;

import static org.junit.Assert.*;

import name.marz.to.go.ahg.core.Parameters;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Test;

public class HttpUtilTest {
	@Test
	public void testGetParametersFromInputTagsElem() {
		String html = new String();
		html += "<input name=\"test1\" value=\"test1value\"/>";
		html += "<input name=\"test2\" value=\"test2value\"/>";
		Document doc = Jsoup.parse(html);
		
		Parameters p = HttpUtil.getParametersFromInputTags(doc.getAllElements());
		
		assertSame("size",2, p.size());
		assertEquals("input 1","test1value", p.get("test1"));
		assertEquals("input 2","test2value", p.get("test2"));
	}
	
	
	@Test
	public void testGetParametersFromForm() {
		String html = new String();
		html += "<html><body>";
		html += "<form name=\"testform\">";
		html += "<input name=\"test1\" value=\"test1value\"/>";
		html += "<input name=\"test2\" value=\"test2value\"/>";
		html += "<select name=\"test3\">";
		html += "<option value=\"test3value\" selected>";
		html += "<option value=\"test3-2value\">";
		
		html += "</select>";
		html += "</form>";
		html += "</body></html>";
		Document doc = Jsoup.parse(html);
		
		Parameters p = HttpUtil.getParametersFromFormTag(doc,"testform");
		
		assertSame("size",3, p.size());
		assertEquals("input 1","test1value", p.get("test1"));
		assertEquals("input 2","test2value", p.get("test2"));
		assertEquals("select 3","test3value", p.get("test3"));
	}

}
